package net.xiduth.game.player.controlers;

import net.xiduth.game.Animation;
import net.xiduth.game.Graphics;
import net.xiduth.game.WorldObject;
import net.xiduth.game.WorldTile;
import net.xiduth.game.player.Player;
import net.xiduth.game.tasks.WorldTask;
import net.xiduth.game.tasks.WorldTasksManager;

public class PuroPuro extends Controler{


	@Override
	public void start() {
        Teleport(player, 2592, 4321, 0, 2);
	}
	
	public void Teleport(final Player player, final int x, final int y, 
			final int p, final int BlackOut) {
		WorldTasksManager.schedule(new WorldTask() {
			int loop;

			@Override
			public void run() {
				if (loop == 0) {
					player.lock();
					player.setNextAnimation(new Animation(6601));
					player.setNextGraphics(new Graphics(1118));
				} else if (loop == 5) {
					player.setNextWorldTile(new WorldTile(2592, 4321, 0));
					player.getPackets().sendBlackOut(BlackOut);
					player.setNextAnimation(new Animation(-1));
					player.setNextGraphics(new Graphics(-1));
					player.unlock();
					stop();
				}
				loop++;
			}
		}, 0, 1);
	}
	
	@Override
	public boolean processObjectClick1(WorldObject object) {
		int id = object.getId();
		if (id == 1) {
			player.getPackets().sendGameMessage("hi");
			return true;
		}
		return false;
	}
	
	private void Forceleave(boolean logout) {
		player.getPackets().sendBlackOut(0);
		removeControler();
	}
	
	@Override
	public boolean sendDeath() {
		Forceleave(false);
		return true;
	}
	
	@Override
	public void magicTeleported(int type) {
		Forceleave(false);
	}
	
	@Override
	public boolean login() {
		player.getPackets().sendBlackOut(2);
		return false;
	}

	@Override
	public boolean logout() {
		return false;
	}
	
	@Override
	public void forceClose() {
		Forceleave(true);
	}

}